package com.da.javatest.niuke.baodian;

import java.util.Arrays;

/**
 * @author chenlida
 * @date 2020/10/4 16:06
 * https://www.nowcoder.com/practice/c95aac1506574dfc8ad44c3939c6739d?tpId=8&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C7Clearer {
    public static void main(String[] args) {
        int d[][] = {{1, 2, 3}, {0, 1, 2}, {0, 0, 1}};
        System.out.println(Arrays.deepToString(clearZero(d, 3)));
    }

    public static int[][] clearZero(int[][] mat, int n) {
        int x[] = new int[n];
        int y[] = new int[n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == 0) {
                    x[i]++;
                    y[j]++;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (x[i] != 0 || y[j] != 0) {
                    mat[i][j] = 0;
                }
            }
        }
        return mat;
    }
}
